﻿@using ZhouYu.DreamTour.Model;
@using ZhouYu.DreamTour.Web.Models;
@{
    //调用根据Id获取地方特产信息
    Goods goods = Model as Goods;
    //地方特产页面图片展示
    var SpecialtyPicture = ViewBag.SpecialtyPicture as List<Picture>;
    //根据用户Id查询商品配送地址
    var CheckAllDeliAdress = ViewBag.CheckAllDeliAdress as List<DeliveryAddress>;
    var UserInfo = UserInfoContext.userInfoContext.UserInfo;
}
<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>中国梦想游-商品拍下页</title>
    <link href="~/css/style.css" rel="stylesheet" type="text/css" />
    <link href="~/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/js/jquery-1.9.1.min.js"></script>
    <script src="~/layui-v2.5.4/layui/lay/modules/layer.js"></script>
    <script src="~/layui-v2.5.4/layui/layui.js"></script>
    <link href="~/layui-v2.5.4/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="~/layui-v2.5.4/layui/css/modules/layer/default/layer.css" rel="stylesheet" type="text/css" />

</head>
<body>
    <div class="top_hw clearfix">
        <div class="top_h clearfix">
            <div class="top_hl"><span>欢迎来到中国梦想游，让你的梦想全程免费自由行！</span> 预定热线：<b>0571-63322269</b></div>
            <div class="top_hr">
                @if (UserInfo == null)
                {
                    <a href="/Home/User_Register">会员注册</a>
                    <span>|</span> <a href="/Home/User_Login">登录</a>
                    <span>|</span> <a href="#">梦想收藏</a> <span>|</span> <a href="#">设为首页</a>
                    @*<a>
                欢迎你，来到新世界旅行网！
            </a>*@
                }
                else
                {
                    <a href="/Home/User_Center">会员中心</a>
                    <span>|</span> <a href="#">梦想收藏</a> <span>|</span> <a href="#">设为首页</a> <span>|</span> <a href="/Login/LoginOut">退出</a> <span>|</span>
                    <a>
                        欢迎你，<span>@UserInfo.User_Name</span>来到新世界旅行网！
                    </a>
                }
            </div>
        </div>
    </div>
    <div class="head_w">
        <div class="head_t clearfix">
            <div class="logo"><img src="~/images/logo.jpg"></div>
            <div class="rx_line"><img src="~/images/rx.jpg"></div>
        </div>
    </div>
    <div class="mainNav clearfix">
        <ul class="Nav_ul">
            <li><a href="/Home/Index">首页</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Route">旅游路线</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Scenic">旅游景点</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/CateringAccommodation">餐饮住宿</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Traffic_DatailsOne">交通线路</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Group">旅游团购</a><img src="~/images/nav_line.jpg"></li>
            <li class="cur"><a href="/Home/Specialty">地方特产</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/AutoGenerationIntro">自动生成简介</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Team_Join">团队简介</a><img src="~/images/nav_line.jpg"></li>
            <li><a href="/Home/Itinerary_Details">行程导航</a></li>
        </ul>
    </div>
    <div class="b_wrap">
        <div class="current"><span>当前所在地：</span><a href="/Home/Index">首页</a> >> <a href="/Home/Specialty">地方特产</a> >> <a href="#">商品详情</a></div>
        <div class="sp_lc"><center><img src="~/images/sp_lc02.jpg"></center></div>
        <div class="sp_time"></div>
        <div class="sp_cart clearfix">
            @*<div class="sp_state">购物车状态： <img src="~/images/sp_zt.jpg"> 8/50</div>*@
            <div class="sp_ex">商品总价（不含运费）：<b><span class="total">￥@goods.Discount</span></b> <a href="#">结算</a></div>
        </div>
        <div class="sp_address clearfix">
            <div class="add_tit clearfix"><b>确认收货地址</b> <a href="/Home/User_Address">管理收货地址</a></div>
            <div class="add_con">
                @if (CheckAllDeliAdress.Count != 0)
                {
                    <div class="add_clu clearfix">
                        <div class="sp_js">寄送至</div>
                        @for (int i = 0; i < CheckAllDeliAdress.Count; i++)
                        {
                            <div class="sp_dz">
                                <label>
                                    <input type="radio" class="radio" name="radio" checked id="radio" value="radio">
                                </label>
                                <span style="color:black">@CheckAllDeliAdress[i].Delivery_Adress</span>
                                <input type="hidden" class="Delivery_Name" value="@CheckAllDeliAdress[i].Delivery_Name" />
                                <input type="hidden" class="Delivery_TelPhone" value="@CheckAllDeliAdress[i].Delivery_TelPhone" />
                            </div>
                            if (i == 0)
                            {
                                <div class="mx_add"><a href="#">默认地址</a>   @*<a class="alter" href="#">修改本地址</a>*@</div>
                                break;
                            }
                        }
                    </div>
                    for (int i = 0; i < CheckAllDeliAdress.Count; i++)
                    {
                        if (i == 0)
                        {
                            continue;
                        }
                        <div class="add_clu01 clearfix">
                            <label><input type="radio" class="radio" name="radio" id="radio01" value="radio"></label>
                            <span style="color:black">@CheckAllDeliAdress[i].Delivery_Adress</span>
                            <input type="hidden" class="Delivery_Name" value="@CheckAllDeliAdress[i].Delivery_Name" />
                            <input type="hidden" class="Delivery_TelPhone" value="@CheckAllDeliAdress[i].Delivery_TelPhone" />
                        </div>
                        if (i == 1)
                        {
                            break;
                        }
                    }


                    for (int i = 0; i < CheckAllDeliAdress.Count; i++)
                    {
                        if (i <= 1)
                        {
                            continue;
                        }
                        <div class="add_clu01 clearfix" style="display:none" id="other">
                            <label><input type="radio" class="radio" name="radio" id="radio01" value="radio"></label>
                            <span style="color:black">@CheckAllDeliAdress[i].Delivery_Adress</span>
                            <input type="hidden" class="Delivery_Name" value="@CheckAllDeliAdress[i].Delivery_Name" />
                            <input type="hidden" class="Delivery_TelPhone" value="@CheckAllDeliAdress[i].Delivery_TelPhone" />
                        </div>
                    }
                    <div class="qt_add clearfix">
                        <a href="#" class="" id="UseOtherAddress">使用其它地址</a>
                    </div>
                }
                else
                {
                    <span style="color:red;font-size:18px">您还没有添加收货地址，请点击管理收货地址进行添加</span>
                }
            </div>
        </div>
        <table class="sp_tab" width="980" border="0" cellspacing="0" cellpadding="0">
            <caption>确认订单信息</caption>
            <thead>
                <tr>
                    <th width="335">产品信息</th>
                    <th width="64">赠送积分</th>
                    <th width="158">单价（元）</th>
                    <th width="63">数量</th>
                    <th width="63">优惠</th>
                    <th width="158">小计（元）</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <dl class="sp_dl clearfix">
                            <dt>
                                @foreach (var picture in SpecialtyPicture)
                                {
                                    if (goods.GoodsId == picture.GoodsId && picture.Is_Master == 1)
                                    {
                                        <img src="@picture.PictureUrl" id="Orde_PictureUrl" style="width:100%;margin-left:20%">
                                    }
                                }
                            </dt>
                            <dd>
                                <p style="margin-left:22%;margin-top:6%">
                                    <span id="Order_ProInfo">@goods.GoodsName</span>
                                </p>
                            </dd>
                        </dl>
                    </td>
                    <td id="score">@goods.Discount</td>
                    <td>@goods.Discount</td>

                    <!--数量-->
                    <td>

                        <input id="min" name="" style="width:20%" type="button" value="-">

                        <input id="num" style="width:25%" name="num" type="text" value="1" readonly="true" onchange="setTotal();">

                        <input id="add" name="" style="width:20%" type="button" value="+">

                    </td>

                    <td style="width:20%"><span style="margin-left:10%">暂无优惠！</span></td>
                    <td class="fn_o"><span id="totalPrice">@goods.Discount</span><b>元</b></td>

                </tr>
            </tbody>
        </table>
        <input type="hidden" id="Order_No" name="Order_No" value="" />
        <table class="sp_info" width="980" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td class="ly_td" width="555" rowspan="2">给卖家留言：<input type="text" id="Order_Content" value="" placeholder="" style="width:50%"></td>
                <td class="ys_td" width="423">
                    运送方式：
                    <select name="">
                        <option>顺丰快递</option>
                    </select><b>包邮</b>
                </td>
            </tr>
            <tr>
                <td>运费险：<span style="margin:0 20px;">购买退货运费险，退货可赔付9元 </span>   <b style="color:#666;">0.00元</b></td>
            </tr>
            <tr>
                <td class="hj_td " colspan="2" align="right">店铺合计（不含运费）：<b style="font-size:16px;"><span class="total" id="total">@goods.Discount</span></b></td>
            </tr>
        </table>
        <div class="sp_pay_wrap clearfix">
            <div class="sp_pay">
                <div class="pay_con">
                    <p>可获积分：<span id="score1" style="color:dimgray;font-size:14px">@goods.Discount</span><span style="color:dimgray;font-size:14px">点</span> @*<b>实付款：</b><span id="totalPrice"></span>*@</p>
                    <p>
                        <b>寄送至:</b>
                        <span id="address" style="color:dimgray;font-size:16px"></span>

                    </p>
                    <p><b>收货人:</b><span id="Delivery_Name" style="color:dimgray;font-size:14px"></span><span id="Delivery_TelPhone" style="color:dimgray;font-size:14px;margin-left:2%"></span></p>
                </div>
                <div class="sp_button"><a class="pay_back" href="javascript:history.go(-1)">返回</a> <a class="pay_order" id="Order" href="#">提交订单</a></div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
    $(function () {

        //默认配送地址、收货人、收货人电话
        var radio = $(".radio");
        radio.each(function (i, data) {
            if ($(this).prop("checked")) {
                $("#address").text($(this).parent().next().text());
                $("#Delivery_Name").text($(this).parent().next().next().val());
                $("#Delivery_TelPhone").text($(this).parent().next().next().next().val());
            }
        });

        //配送地址、收货人、收货人电话单选按钮改变事件
        $(".radio").change(function () {
            var radio = $(this);
            radio.each(function (i, data) {
                if ($(this).prop("checked")) {
                    $("#address").text($(this).parent().next().text());
                    $("#Delivery_Name").text($(this).parent().next().next().val());
                    $("#Delivery_TelPhone").text($(this).parent().next().next().next().val());
                }
            });
        });

        //使用其他地址按钮点击事件
        $("#UseOtherAddress").click(function () {
            $("#other").toggle();
        });

        //根据选择的数量计算总价，并显示出来
        function setTotal() {
            var t = $("#num");
            if (/\D/.test(t.val())) {//检查用户输入的值是否是数字
                layer.msg('请您输入正确的数量！', {
                        title: '提示框',
                        icon: 1,
                        time: 1000
                    });
                t.val(1);
                $("#score").text(@goods.Discount);
                $("#score1").text(@goods.Discount);
                $("#totalPrice").text(@goods.Discount);
                $(".total").text(@goods.Discount+"元");
            }
            else {//如果输入合法
                $("#score").text(t.val() * @goods.Discount);
                $("#score1").text(t.val() * @goods.Discount);
                $("#totalPrice").text(t.val() * @goods.Discount);
                $(".total").text(t.val() * @goods.Discount+"元");
                if (t.val() > 10) {
                    layer.msg('您真的准备一次购买这么多？', {
                        title: '提示框',
                        icon: 1,
                        time: 1000
                    });
                    $("#score").text(t.val() * @goods.Discount);
                    $("#score1").text(t.val() * @goods.Discount);
                    $("#totalPrice").text(t.val() * @goods.Discount);
                    $(".total").text(t.val() * @goods.Discount+"元");
                }
            }
        }

        //这里是加减按钮都启用的情况
        $(function () {
            var t = $("#num");
            $("#add").click(function () {
                t.val(parseInt(t.val()) + 1)
                setTotal();
            })
            $("#min").click(function () {
                if (t.val() > 1) {
                    t.val(parseInt(t.val()) - 1);
                }
                else {
                    layer.msg('至少购买一件哦！', {
                        title: '提示框',
                        icon: 1,
                        time: 1000
                    });
                }
                setTotal();
            })
        });


        //提交订单按钮点击事件
        $("#Order").click(function () {
            //获取页面值
            var data = {};            
            data.Order_ProInfo = $("#Order_ProInfo").text();
            data.Order_Money = $("#totalPrice").text();
            data.OrderOver_Name = $("#Delivery_Name").text();
            data.Orde_PictureUrl = $("#Orde_PictureUrl").attr("src");
            data.Order_Content = $("#Order_Content").val();
            data.OrderOver_Tel = $("#Delivery_TelPhone").text();
            data.OrderOver_Address = $("#address").text();
            data.Order_No = $("#Order_No").val();
            var total = $("#total").text(); 
            var Order_No = $("#Order_No").val();
            $.ajax({
                url: "/Specialty/AddGoodsOrderInfo",
                type: "post",
                data: data,
                success: function (result) {
                    if (result.Success) {
                            //提交成功则跳转支付页面
                        location.href = "/Home/Specialt_Payment?Order_ProInfo=@goods.GoodsName&Order_Content=@goods.Describe&GoodsId="+@goods.GoodsId+"&total="+ total+"&Order_No="+Order_No;
                            layer.close(index);
                    }
                    else {
                        layer.msg('系统繁忙,请稍后再试！', {
                            title: '提示框',
                            icon: 0,
                            time: 1000
                        });
                    }
                }
            });
        });

        //动态生成订单号
        function GetDateNow() {
            var vNow = new Date();
            var sNow = "";
            sNow += String(vNow.getFullYear());
            sNow += String(vNow.getMonth() + 1);
            sNow += String(vNow.getDate());
            sNow += String(vNow.getHours());
            sNow += String(vNow.getMinutes());
            sNow += String(vNow.getSeconds());
            sNow += String(vNow.getMilliseconds());
            document.getElementById("Order_No").value = sNow;
        }
    GetDateNow();
    });
</script>

